function [ rect_list ] = jitterRect(rect, margin, inc, params)

if nargin < 3
    error('Missing some arguments');
end
min_width = floor(0.5*rect(3));
max_width = rect(3) + 2*margin;
min_height = floor(0.5*rect(3));
max_height = rect(4) + 2*margin;
% check if result would be beyond bounds of image

if nargin == 4
    if isfield(params, 'min_width')
        min_width = params.min_width;
    end
    if isfield(params, 'max_width')
        max_width = params.max_width;
    end
    if isfield(params, 'min_height')
        min_height = params.min_height;
    end
    if isfield(params, 'max_height')
        max_height = params.max_height;
    end
end
rect_list = [];

start_x = rect(1);
start_y = rect(2);

for ix = start_x-margin:inc:start_x+margin
    for jx = start_y-margin:inc:start_y+margin
        for xx = min_width:inc:max_width
            yy = min_height:inc:max_height;
            cur_elem = [repmat(ix,length(yy),1) repmat(jx,length(yy),1) repmat(xx,length(yy),1) yy'];
            rect_list = [rect_list; cur_elem];
        end
    end
end
end
